//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tyr_drones\fn_disconnectDrone.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_player","_drone","_pos","_dummy","_crew_dummy","_crew_drone"];
PARAMS_2(_player,_drone);

if (!isnil "_player" && !isnil "_drone" && {!isnull _player} && {!isnull _drone} && {isPlayer _player}) then {
	if (!isUavConnected _drone) exitWith { TRACE("UAV Not Connected"); };
	if (getConnectedUav _player != _drone) exitWith { TRACE("Not the UAV of this player"); };
	_crew_drone = crew _drone;
	_pos = [0,0,10000 + random(1000)];
	_dummy = GVAR(DUMMY_DRONE_TYPE) createVehicleLocal _pos;
	_dummy setPos _pos;
	_dummy hideObject true;
	createVehicleCrew _dummy;
	_crew_dummy = crew _dummy;
	sleep 0.5;
	{ _x setDamage 1.1;
	} foreach _crew_drone;
	sleep 1;
	player connectTerminalToUav _dummy;
	{ if (!isnull _x) then { deleteVehicle _x };
	} foreach _crew_drone;
	createVehicleCrew _drone;
	
	{ _x setDamage 1.1;
	} foreach _crew_dummy;
	sleep 0.5;
	{ if (!isnull _x) then { deleteVehicle _x };
	} foreach _crew_dummy;
	deleteVehicle _dummy;
};

TRACE("End");
TMFPROFILERSTOP;
